-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deletion - based on user input.cpp
47 lines (40 loc) · 1.16 KB
/
Deletion - based on user input.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
using namespace std;
void deletion(){
int size, loop, position, value;
cout << "Enter the size of array: ";
cin >> size;
int A[size];
for( int i = 0; i < size; i++ ){
cout << "Enter a value for the position of [" << i+1 << "]: ";
cin >> A[i];
}
cout << endl << "Array is => ";
for( int i = 0; i < size; i++ ){
cout << "[" << A[i] << "] ";
}
cout << endl;
cout << "How many values do you want to delete from this array?: ";
cin >> loop;
for( int i = 0; i < loop; i++ ){
cout << endl << "[Delete-"<<i+1<<"] Enter the Postion: " ;
cin >> position;
position = position-1;
if(position >= 0 && position < size){
for( int x = position; x < size-(i+1); x++ ){
A[x] = A[x+1];
}
cout << "Array is => ";
for(int y = 0; y < size-(i+1); y++){
cout << "[" << A[y] << "] ";
}
cout << endl;
}else{
cout << "Invalid position! The position must be less than or equal to the A length";
break;
}
}
}
int main(){
deletion();
}